<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<form id="uploadForm">
    <p>指定文件名： <input type="text" name="filename" value=""/></p>
    <p>上传文件： <input type="file" name="file"/></p>
    <input type="button" value="上传" onclick="doUpload()"/>
</form>
<textarea id="con" style="height: 500px;width: 800px">
</textarea>
<script src="page/jquery-1.10.1.min.js"></script>
<script>


    function doUpload() {
        var formData = new FormData($("#uploadForm")[0]);
        $.ajax({
            url: 'http://10.226.78.184:8080/miaoxie/baidu/ocr/getBaiduOcr.action',
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (returndata) {
                var con = "";

                var result = returndata.result;
                //图像方向，当detect_direction=true时存在。
                // - -1:未定义，- 0:正向，- 1: 逆时针90度，- 2:逆时针180度， - 3:逆时针270度
                var direction = result.direction;
                //识别结果数组
                var words_result = result.words_result;
                //识别结果数，表示words_result的元素个数
                var words_result_num = result.words_result_num;
                con += "图片方向："+direction+"(-1:未定义，- 0:正向，- 1: 逆时针90度，- 2:逆时针180度， - 3:逆时针270度)"+"\n";
                con +="识别行数："+words_result_num+"\n";
                for (var i=0;i<words_result.length;i++)
                {
                    var resultTemp = words_result[i];
                    //识别结果字符串
                    var words = resultTemp.words;
                    //行置信度平均值
                    var average = resultTemp.probability.average;
                    //行置信度方差
                    var variance = resultTemp.probability.variance;
                    //行置信度最小值
                    var min = resultTemp.probability.min;


                    con +="第"+i+1+"行识别内容："+words+"---行置信度平均值:"+average+"---行置信度方差+"+average+"---行置信度最小值+"+average+"\n\n\n\n";
                }
                $("#con").html(con);
            },
            error: function (returndata) {
                alert(returndata);
            }
        });
    }
</script>
</body>
</html>
